//
//  BLError.swift
//  SportLive
//
//  Created by cgw on 2020/8/18.
//  Copyright © 2020 Met. All rights reserved.
//

import Foundation

class BLError: NSObject {
    static let defaultErrCode = -1
    static let defaultErrKey = "BLErrorDefaultKey"
    static func error(msg: String) -> NSError {
        
        let ms = msg == "" ? "未知错误" : msg
        return NSError.init(domain: "BLError", code: -1, userInfo: [defaultErrKey:ms])
    }
    
    static func errorMsg(err: NSError?) -> String {
        let msg = err?.userInfo[defaultErrKey]
        if msg != nil {
            return msg as! String
        }
        else{
            return "未知错误"
        }
    }
}


extension UIViewController{
    func showError(err: NSError?) {
        let msg = BLError.errorMsg(err: err)
        self.showErrorMsg(msg)
    }
    
    func showHud() -> BLProgressHUD? {
        return BLProgressHUD.show("", in: self.view)
    }
}

